package com.linln.modules.modules.reply.service.impl;

import com.linln.common.data.PageSort;
import com.linln.common.enums.StatusEnum;
import com.linln.modules.modules.reply.domain.Reply;
import com.linln.modules.modules.reply.repository.ReplyRepository;
import com.linln.modules.modules.reply.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author hct
 * @date 2019/10/11
 */
@Service
public class ReplyServiceImpl implements ReplyService {

    @Autowired
    private ReplyRepository replyRepository;

    /**
     * 根据ID查询数据
     * @param id 主键ID
     */
    @Override
    @Transactional
    public Reply getById(Long id) {
        return replyRepository.findById(id).orElse(null);
    }

    /**
     * 获取分页列表数据
     * @param example 查询实例
     * @return 返回分页数据
     */
    @Override
    public Page<Reply> getPageList(Example<Reply> example) {
        // 创建分页对象
        PageRequest page = PageSort.pageRequest();
        return replyRepository.findAll(example, page);
    }
    public List<Reply> getList(List<Long> ids){
    	return replyRepository.findAllById(ids);
    }

    /**
     * 保存数据
     * @param reply 实体对象
     */
    @Override
    public Reply save(Reply reply) {
        return replyRepository.save(reply);
    }
    @Override
   public Boolean deleteById(Long id) {
    	boolean isOk=false;
    	try {
    	replyRepository.deleteById(id);
    	isOk=true;
    	}catch(Exception e) {
    		
    	}
    	return isOk;
    }
    
}